import csv

'''
读写csv类
'''


class CsvWriter:
    def __init__(self, trainPath, testPath, validationPath, writeType):
        '''
        :param trainPath: 训练集路径
        :param testPath: 测试集路径
        :param validationPath: 验证集路径
        :param writeType: 写入方式(覆盖或追加)
        '''
        # 以此用写入csv的方式打开三个文件
        self.trf = open(trainPath, writeType, newline='', encoding='utf-8')
        self.tef = open(testPath, writeType, newline='', encoding='utf-8')
        self.vf = open(validationPath, writeType, newline='', encoding='utf-8')
        self.trw = csv.writer(self.trf)
        self.tew = csv.writer(self.tef)
        self.vw = csv.writer(self.vf)

    def close(self):
        # 一次性关闭所有文件
        self.trf.close()
        self.tef.close()
        self.vf.close()
